# !/bin/bash -x

set -e -o pipefail

# verify Emscripten version
emcc -v

# configure FFMpeg with Emscripten
CONFIG_ARGS=(
  --prefix=/src/emccbuild/
  --cc="emcc"
  --cxx="em++"
  --ar="emar"
  --target-os=none
  --arch=x86_32
  --disable-logging
  --disable-programs
  --disable-ffmpeg
  --disable-ffplay
  --disable-ffprobe
  --disable-doc
  --disable-swresample
  --disable-postproc
  --disable-avfilter
  --disable-pthreads
  --disable-w32threads
  --disable-os2threads
  --disable-network
  --disable-everything
  --disable-asm
  --disable-debug
  --enable-protocol=file
  --enable-gpl
  --enable-version3
  --enable-cross-compile
  --enable-demuxer=mov
  --enable-demuxer=matroska
  --enable-demuxer=flv
  --enable-demuxer=avi
  --enable-decoder=h264
  --enable-decoder=hevc
  --enable-decoder=mpeg4
  --enable-decoder=vp8
  --enable-decoder=vp9
  --enable-decoder=wmv3
)
emconfigure /src/FFmpeg-release-4.4/configure "${CONFIG_ARGS[@]}"

# build dependencies
emmake make -j4

emmake make install